<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MVCWeb.Models.Event>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>
<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Edit</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function deleteRecord(recordId) {
            if (confirm("Are you sure to delete this event?")) {
                // Perform delete
                var action = '<%= Url.Action("Delete", "Event") %>/' + recordId;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(deleteCompleted);
                request.invoke();
            }
        }

        function deleteCompleted() {
            // Reload page  
            window.back();
        }    
    </script>

    <script type="text/javascript">

        $(document).ready(function() {
            $("#EventDate").datepicker({ changeMonth: true, changeYear: true, showOn: 'button', buttonImage: '/Content/Images/Icons/calendar.gif', buttonImageOnly: true });

            $("#EventForm").validate({
                rules:
            {
                Name:
                {
                    required: true
                }
            },

                messages:
            {
                Name:
                {
                    required: "Event name must be entered."
                }
            }
            });
            $("#submit_view").click(function() {
                $("#IsRedirectToView").val("true");
            });

        });
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
    <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <br />
    <%= Html.ValidationSummary() %>
    <% using (Html.BeginForm("Edit", "Event", FormMethod.Post, new { id = "EventForm" }))
       {%>
    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="EventType">
                Event Type:</label>
            <%= Html.DropDownList("EventType", (SelectList)ViewData["EventTypes"])%>
        </p>
        <p>
            <label for="EventType">
                Or Create Event Type:</label>
            <%= Html.TextBox("NewEventType")%>
        </p>
        <p>
            <label for="Name">
                Name:</label>
            <%= Html.TextBox("Name",Model.Name) %>
            <%= Html.ValidationMessage("Name", "*") %>
        </p>
        <p>
            <label for="EventDate">
                Event Date:</label>
            <%= Html.TextBox("EventDate",Model.EventDate.Value.ToShortDateString()) %>
            <%= Html.ValidationMessage("EventDate", "*") %>
        </p>
        <p>
            <label for="MustNotify">
                Must Notify:</label>
            <%= Html.CheckBox("MustNotify",Model.MustNotify) %>
            <%= Html.ValidationMessage("MustNotify", "*") %>
        </p>
        <p>
            <label for="Active">
                Active:</label>
            <%= Html.CheckBox("Active",Model.Active)%>
        </p>
        <%--<p>
                <label for="CommunityId">CommunityId:</label>
                <%= Html.TextBox("CommunityId") %>
                <%= Html.ValidationMessage("CommunityId", "*") %>
            </p>
            <p>
                <label for="ChairUserId">ChairUserId:</label>
                <%= Html.TextBox("ChairUserId") %>
                <%= Html.ValidationMessage("ChairUserId", "*") %>
            </p>--%>
        <p>
            <%= Html.Hidden("IsRedirectToView")%>
            <input id="submit" name="submit" type="submit" value="Update" />
            <input id="submit_view" name="submit_view" type="submit" value="Update & View" />
            <% if (Roles.IsUserInRole("Administrators"))
               { %>
            <input id="delete" name="delete" type="submit" value="Delete" onclick="deleteRecord(<%=Model.EventId%>); return false;" />
            <% } %>
            <input type="reset" value="Reset" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%=Html.ActionLink("Back to List", "Index") %>
    </div>
</asp:Content>
